package com.guida.config;

import com.guida.interceptor.ResourceInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@ComponentScan("com.guida.controller")//等同于开启包扫描，com.guida.controller
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer {

    //开启对静态资源的访问
    //类似于:<mvc:default-servlet-handler>


    //自定义拦截器
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    //视图解析器
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/admin/",".jsp");
    }

    /**
     *配置了SpringMVC的相关信息，实现了WebMvcConfigurer接口，这样可以自定义SpringMVC的配置
     * 如自定义拦截器，试图解析器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ResourceInterceptor()).addPathPatterns("/**").excludePathPatterns("/css/**", "/js/**", "/img/**");
    }
}
